package com.exmaple.baidumv;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.view.Window;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.example.baidumv.R;
import com.exmaple.baidumv.fragment.HomeFragment;
import com.exmaple.baidumv.fragment.MeFragment;
import com.exmaple.baidumv.fragment.RankingFragment;
import com.exmaple.baidumv.info.ConFigFile;

public class MainActivity extends FragmentActivity implements  RadioGroup.OnCheckedChangeListener
		 {
	  private static final String TAG = "MainActivity" ;

	  private RadioGroup mRadioGroup ;
	  private MeFragment mMeFragment ;
	  private HomeFragment mHomeFragment;
	  private RankingFragment mRankingFragment;
	@Override
	protected void onCreate(Bundle arg0) {
		// TODO Auto-generated method stub
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		super.onCreate(arg0);
	    setContentView(R.layout.activity_main);
	    ConFigFile.creatSDCardFolder(this);
	    init();
		
	}
	private void init(){
	     mRadioGroup = (RadioGroup)findViewById(R.id.main_tab_group);
	     mRadioGroup.setOnCheckedChangeListener(this);
	     mHomeFragment = new HomeFragment();
	     mRankingFragment = new RankingFragment();
	     mMeFragment = new MeFragment();
	     setPage(mHomeFragment);
	     
	}
	@Override
	public void onCheckedChanged(RadioGroup arg0, int arg1) {
		// TODO Auto-generated method stub
		 switch (arg1) {
         case R.id.home:
        	 setPage(mHomeFragment);
        	 RadioButton btn1 = (RadioButton) findViewById(R.id.home);
             btn1.setChecked(true);
             break;
         case R.id.ranking:
        	 setPage(mRankingFragment);
        	 RadioButton btn2 = (RadioButton) findViewById(R.id.ranking);
             btn2.setChecked(true);
             break;
         case R.id.me :
        	 setPage(mMeFragment);
        	 RadioButton btn3 = (RadioButton) findViewById(R.id.me);
             btn3.setChecked(true);
             break;
         default:
             break;
     }
	}
	
	public void setPage(Fragment arg0) {
		FragmentTransaction ft = MainActivity.this.getSupportFragmentManager()
				.beginTransaction();
		ft.replace(R.id.fragment, arg0);
		ft.commit();
	}
	
}
